package breeze.lepei.der.utils;
import java.util.Properties;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import javax.mail.MessagingException;
import javax.mail.Message;
import java.util.Date;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import java.io.UnsupportedEncodingException;

public class SendEmailUtil {
	public static final String fromEmail="breeze258369@163.com";
	public static final String key="IHGCUXRHKURBZZXQ";
	
	public static void sendEmail(String emailAdress,String emailTitle,String emailContent) throws MessagingException, UnsupportedEncodingException{
		Properties properties = new Properties();
		properties.setProperty("mail.smtp.host","smtp.163.com");
		properties.setProperty("mail.smtp.auth","true");
		properties.setProperty("mail.transport.protocol","smtp");
		Session session = Session.getDefaultInstance(properties);
		MimeMessage message = new MimeMessage(session);
		message.setFrom(new InternetAddress(fromEmail,"BREEZE","UTF-8"));
		message.setContent(emailContent,"text/html;charset=UTF-8");
		message.setSubject(emailTitle);
		message.setRecipients(Message.RecipientType.TO,emailAdress);
		message.setSentDate(new Date());
		message.saveChanges();
		Transport transport = session.getTransport();
		transport.connect(fromEmail,key);
		transport.sendMessage(message,message.getAllRecipients());
	}
}
